package com.im.partchat.ui.activity;

import android.os.Bundle;
import android.view.View;
import android.widget.AdapterView;
import android.widget.ListView;

import com.im.partchat.R;
import com.im.partchat.adapter.GroupListAdapter;
import com.im.partchat.base.BaseActivity;
import com.im.partchat.bean.Group;
import com.im.partchat.mvp.persenter.ContactPresenter;

import java.util.ArrayList;
import java.util.List;

import butterknife.BindView;

/**
 * Created by hhz on 2017/7/1.
 */
public class GroupActivtiy extends BaseActivity {
    @BindView(R.id.lv_content)
    ListView lvContent;

    private ContactPresenter presenter;

    private GroupListAdapter mGroupListAdapter;
    private List<Group> groupBeans = new ArrayList<>();

    @Override
    protected int getLayoutId() {
        return R.layout.fragment_group;
    }

    @Override
    protected void initView(Bundle savedInstanceState) {
        super.initView(savedInstanceState);
        mGroupListAdapter = new GroupListAdapter(this, groupBeans);
        lvContent.setAdapter(mGroupListAdapter);
        lvContent.setOnItemClickListener(new AdapterView.OnItemClickListener() {
            @Override
            public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
                if (groupBeans != null && groupBeans.size() > 0) {
                    //发起群聊
                }
            }
        });
    }

    @Override
    protected void initData() {
        presenter = new ContactPresenter(this);
        presenter.getGroup();
    }

    @Override
    public void onLoadDataSuccess(Object o, String flag) {
        if (null == o) {
            showEmpty();
        } else {
            List<Group> data = (List<Group>) o;
            if (data != null && data.size() > 0) {
                groupBeans.clear();
                groupBeans.addAll(data);
                mGroupListAdapter.notifyDataSetChanged();
                showPageSuccess();
            } else {
                groupBeans.clear();
                mGroupListAdapter.notifyDataSetChanged();
                showEmpty();
            }
        }

    }

}
